#include "SDLScene.h"

SDLScene::SDLScene(std::string _name)
	: m_Name(_name)
{
}

SDLScene::SDLScene(const SDLScene& _source)
	: m_Name(_source.m_Name)
{
	std::list<IObject*>::const_iterator iter = _source.m_Components.begin();

	while(iter != _source.m_Components.end())
	{
		m_Components.push_back(*iter);
		iter++;
	}
}

SDLScene::SDLScene(const SDLScene *const _source)
	: m_Name(_source->m_Name)
{
	std::list<IObject*>::const_iterator iter = _source->m_Components.begin();

	while(iter != _source->m_Components.end())
	{
		m_Components.push_back(*iter);
		iter++;
	}
}

SDLScene::~SDLScene()
{

}

SDLScene& SDLScene::operator=(const SDLScene& _source)
{
	m_Name = _source.m_Name;
	std::list<IObject*>::const_iterator iter = _source.m_Components.begin();

	while(iter != _source.m_Components.end())
	{
		m_Components.push_back(*iter);
		iter++;
	}

	return *this;
}

bool SDLScene::AddComponent(IObject* _component)
{
	if(!Contains(_component))
	{
		m_Components.push_back(_component);
		return true;
	}

	return false;
}

bool SDLScene::RemoveComponent(IObject* _component)
{
	if(Contains(_component))
	{
		m_Components.remove(_component);
		return true;
	}

	return false;
}
void SDLScene::Start()
{
	std::list<IObject*>::iterator iter;

	for(iter = m_Components.begin(); iter != m_Components.end(); iter++)
	{
		(*iter)->Start();
	}
}

void SDLScene::Update()
{
	std::list<IObject*>::iterator iter;

	for(iter = m_Components.begin(); iter != m_Components.end(); iter++)
	{
		(*iter)->Update();
	}
}

void SDLScene::Stop()
{
	std::list<IObject*>::iterator iter;

	for(iter = m_Components.begin(); iter != m_Components.end(); iter++)
	{
		(*iter)->Stop();
	}
}

void SDLScene::Draw()
{
	std::list<IObject*>::iterator iter;

	for(iter = m_Components.begin(); iter != m_Components.end(); iter++)
	{
		(*iter)->Draw();
	}
}

bool SDLScene::Contains(IObject* _component) const
{
	std::list<IObject*>::const_iterator iter;

	for(iter = m_Components.begin(); iter != m_Components.end(); iter++)
	{
		if( (*iter) == _component)
			return true;
	}
	return false;
}